package cn.liyicun.school.car2.service;

import java.util.HashMap;
import java.util.Map;

import cn.liyicun.school.car2.model.LineInfo;
import cn.liyicun.school.car2.model.PlaceInfo;

public class CacheModelService {

	public static CacheModelService dao = new CacheModelService();

	Map<Integer, PlaceInfo> placeInfoMap = new HashMap<>();
	Map<Integer, LineInfo> lineInfoMap = new HashMap<>();

	public void clear() {
		placeInfoMap.clear();
		lineInfoMap.clear();
	}

	public PlaceInfo placeInfo(Integer id) {
		PlaceInfo info = placeInfoMap.get(id);
		if (info != null)
			return info;
		info = PlaceInfo.dao.findById(id);
		if (info != null) {
			placeInfoMap.put(id, info);
		}
		return info;

	}

	public LineInfo lineInfo(Integer id) {
		LineInfo info = lineInfoMap.get(id);
		if (info != null)
			return info;
		info = LineInfo.dao.findById(id);
		if (info != null) {
			lineInfoMap.put(id, info);
		}
		return info;

	}
}
